import sun.plugin2.gluegen.runtime.CPU;

import javax.naming.spi.DirectoryManager;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

/**
 * 注销用户
 * SQL语句:delete from userinfo where username=?
 */
public class JDBCDemo3 {
    public static void main(String[] args) {
         /*
        1.接收用户输入
        2.加载数据库驱动
        3.创建数据库对象连接
        4.创建执行对象
        5.执行sql语句
        6.断开连接
     */
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入用户名:");
        String username=sc.nextLine();
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/tedu","root","root");
            Statement statement = connection.createStatement();
            String sql="delete from userinfo where username='"+username+"' ";
            int i = statement.executeUpdate(sql);
            if (i>1){
                System.out.println("注销用户成功");
            }else {
                System.out.println("注销用户失败");
            }
            connection.close();
        } catch (ClassNotFoundException | SQLException e) {
            e.printStackTrace();
        }
    }

}
